package tools.nlp;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import opennlp.tools.sentdetect.SentenceDetectorME;
import opennlp.tools.sentdetect.SentenceModel;

public class SentenceDetector {
	private String modelPath = "data/openNLP/bin/en-sent.bin";
	private SentenceDetectorME sd = null;
	
	public SentenceDetector(String path) {
		this.modelPath = path;
		load();
	}
	
	public SentenceDetector() {
		load();
	}
	
	private void load() {
		SentenceModel model = null;
		InputStream modelIn = null;
		
		try {
			modelIn = new FileInputStream(modelPath);
			model = new SentenceModel(modelIn);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (modelIn != null) {
				try {
					modelIn.close();
				} catch (IOException e) {
				}
			}
		}
		sd = new SentenceDetectorME(model);
	}
	
	public SentenceDetectorME getSentenceDetector() {
		return sd;
	}
}
